<!--
 * @Author: your name
 * @Date: 2022-04-20 10:10:02
 * @LastEditTime: 2022-05-14 15:17:14
 * @LastEditors: gong.jiuhui you@example.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\apply\purchaseDetail.vue
-->

<template>
  <div class="applyPayDetail">
    <Navbar
      :appTitle="title"
      ref="element"
      id="topdd"
      @eventGetHeight="getHeight"
    />
    <!--头部-->
    <div class="d-head" id="headdd">
      <div class="content">
        <div class="left">
          <div class="title">
            {{ $route.query.title }}
          </div>
          <div class="row">{{ workOrderInfo.applyNo }}</div>
          <div class="row">
            {{ workOrderInfo.createByText }},{{
              workOrderInfo.createTime
            }}
            发起申请
          </div>
        </div>
        <div class="right">
          <img
            class="rightImg"
            v-if="workOrderInfo.flowStatus == 'RUNNING'"
            src="@/assets/img/shenpizhong.png"
            alt=""
          />
          <img
            class="rightImg"
            v-if="workOrderInfo.flowStatus == 'AGREE'"
            src="@/assets/img/yitongguo.png"
            alt=""
          />
          <img
            class="rightImg"
            v-if="workOrderInfo.flowStatus == 'REFUSE'"
            src="@/assets/img/yijujue.png"
            alt=""
          />
          <img
            class="rightImg"
            v-if="workOrderInfo.flowStatus == 'TERMINATED'"
            src="@/assets/img/yichehui.png"
            alt=""
          />
        </div>
      </div>
    </div>

    <!-- taps-->
    <!--锚点选项卡-->
    <van-tabs v-model="active" scrollspy sticky :offset-top="runingHeight">
      <!--基本信息 -->
      <van-tab title="基本信息" :style="calssDD">
        <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">基本信息</span>
          </div>
          <div class="content">
            <div class="row">
              <span class="r-label">使用日期：</span>
              <span class="r-column">{{ workOrderInfo.useDate }}</span>
            </div>
            <div class="row">
              <span class="r-label">采购事由：</span>
              <span class="r-column">{{ workOrderInfo.reason }}</span>
            </div>
            <div class="row">
              <span class="r-label">附件：</span>
              <span class="r-column" style="flex: 1;">
                <upload
                  class="fileclass"
                  iconType="fj"
                  @fileChange="fileChange"
                  :fileIds="workOrderInfo.attachment"
                  :showUpload="false"
                ></upload>
              </span>
            </div>
          </div>
        </div>
      </van-tab>
      <!--发货明细 -->
      <van-tab title="采购明细">
        <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">采购明细</span>
          </div>
          <div
            class="content"
            v-for="(item, index) in workOrderInfo.erpPurchaseTaskApplyItemVo"
            :key="index"
          >
            <div class="fhrow">
              <img :src="item.picUrl" alt="" class="fhImg" />
              <div class="rt-column">
                <div class="rt-title">
                  {{ item.goodsName }}|{{ item.goodsCode }}|{{ item.spec }}
                </div>
                <div class="rt-row">
                  <div class="column">
                    <span class="column-t">本次采购数量：</span>
                    <span class="column-c">{{ item.num }}{{ item.numUnit }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </van-tab>

      <!--审批流程 -->
      <van-tab title="审批流程" :style="bottomHeight">
        <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">审批流程</span>
          </div>
          <!-- ids="ERP_PURCHASE_TASK_APPLY" -->
          <Examine
            v-if="workOrderInfo.flowInstId"
            type="2"
            :id="workOrderInfo.flowInstId"
            ref="examine"
            :showTitle="false"
          />
        </div>
      </van-tab>
    </van-tabs>

    <!--提交按钮 -->
    <div
      class="search-bottom"
      v-if="
        $route.query.applyType == 'waiterDeal' &&
        workOrderInfo.flowStatus == 'RUNNING'
      "
    >
      <span class="btncancel" @click="cancel">拒绝</span>
      <span class="btnconfirm" @click="confirm">同意</span>
    </div>
  </div>
</template>

<script>
import {
  erpPurchaseTaskApplyQueryById,
  getFileListByIds,
} from "@/api/mobile.js";
import { apiBaseUrlDownload, apiBaseUrlUpload } from "@/utils/request";
import Navbar from "@/components/navBar/navBar_right";
import upload from "@/components/upload/upload";
import Examine from "@/components/examine";
export default {
  name: "recordDetail",
  components: { Navbar, upload, Examine },
  data() {
    return {
      topHeight:"",//导航头的高度
      bodyHeight:"",//获取分辨率 
      runingHeight:"", //锚点选项卡距顶部的高度
      bottomHeight:"padding-bottom:1.5rem",//为了撑开底部 锚点准确
      calssDD: "",//锚点的第一个元素位置
      parentId: "",
      tableData: [],
      workOrderInfo: {},
      title: this.$route.meta.title,
      tabList: [
        { name: "发货记录", value: "1" },
        { name: "开票记录", value: "2" },
        { name: "收款记录", value: "2" },
      ],
      active: 0,
      fileIds: "1514159656052879361,1514159725032402946",
    };
  },
  watch: {
    workOrderInfo(newVal) {
      this.$nextTick(() => {
        //  alert("2")
        this.getAfterHeight()
      
      })
    },
  },
  computed: {},
  mounted() {
  
   
  },
  created() {
    if (this.$route.query.id) {
      this.parentId = this.$route.query.id;
    }
    this.getDetail();
  },
  methods: {
      getHeight(data){
       this.topHeight=data
       this.getAfterHeight()
     },
    getAfterHeight() {
      this.bodyHeight=document.body.clientHeight;//屏幕高度
     
      if(this.bodyHeight>=736){
        this.bottomHeight="padding-bottom:2rem";
      }
      if(this.bodyHeight>=812){
         this.bottomHeight="padding-bottom:2.5rem";
      }
      if(this.bodyHeight>=896){
         this.bottomHeight="padding-bottom:3rem";
      }
      this.bodyHeight=document.body.clientHeight;//屏幕高度
      this.runingHeight =this.topHeight+document.getElementById("headdd").offsetHeight-5;
      // this.runingHeight =this.headheight-5;
      this.calssDD = "margin-top:" + (this.runingHeight - this.topHeight) + "px";
    },
    cancel() {
      // approveType 1:同意 0:拒绝
      this.$router.push({
        path: "/approval",
        query: { approveType: 0, taskId: this.$route.query.taskId },
      });
    },
    confirm() {
      this.$router.push({
        path: "/approval",
        query: { approveType: 1, taskId: this.$route.query.taskId },
      });
    },
    fileChange(ids) {
      console.log(ids);
      this.formData.attachment = ids;
    },
    getDetail() {
      erpPurchaseTaskApplyQueryById(this.parentId).then((res) => {
        if (res.success) {
          if (res.result) {
            this.workOrderInfo = res.result;
            // alert(this.workOrderInfo.flowInstId)
            let tableData = res.result.erpPurchaseTaskApplyItemVo;
            tableData.forEach((item) => {
              if (item.attachment) {
                let ids = item.attachment;
                getFileListByIds({ ids }).then((res) => {
                  if (res.code == 200) {
                    let fileList = "";
                    fileList = res.result;
                    if (fileList.length > 0) {
                      // /jksaas-mgt/mgt/
                      item.picUrl = apiBaseUrlDownload + 'jksaas-mgt/mgt/' + fileList[0].uri;
                      this.tableData.push(item);
                      this.$forceUpdate();
                    } else {
                      item.picUrl = require("@/assets/img/noPicture.jpg");
                      this.tableData.push(item);
                    }
                  }
                });
              } else {
                item.picUrl = require("@/assets/img/noPicture.jpg");
                this.tableData.push(item);
              }
            });
            console.log(tableData, "0.0tableData");
            // this.tableData = tableData
          }
        } else {
          this.$antdMessage.warning(res.message);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.applyPayDetail {
  height: 100vh;
  overflow-y: scroll;
  background: #ffffff;
  // background: green;
  .d-head {
    position: fixed;
    width: 100%;
    padding: 0.16rem 0.16rem 0.16rem 0.16rem;
    background: #ffffff;
    z-index: 999;
    .content {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        width: 2.8rem;
        // border: 1px solid red;
        .title {
          font-size: 0.16rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #191f25;
          line-height: 0.22rem;

          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          -o-text-overflow: ellipsis;
        }
        .row {
          font-size: 0.14rem;
          font-family: PingFang SC;
          font-weight: 400;
          color: #888888;
          margin-top: 0.16rem;
        }
      }
      .right {
        // border: 1px solid red;
        width: 0.6rem;
        .rightImg {
          display: block;
          width: 0.55rem;
          height: 0.55rem;
          //   margin-left: 0.45rem;
          // border: 1px solid blue;
        }
      }
    }
  }

  .otherTaps {
    background: #ffffff;
    padding: 0.16rem;
    border-top: 0.1rem solid rgb(245, 245, 245);

    .title {
      padding-bottom: 0.1rem;
      border-bottom: 1px solid #eeeeee;
      .icon {
        display: inline-block;
        width: 0.03rem;
        height: 0.14rem;
        background: #1890ff;
      }
      .content {
        width: 0.63rem;
        height: 0.16rem;
        font-size: 0.16rem;
        font-family: PingFang SC;
        font-weight: bold;
        color: #191f25;
        line-height: 0.22rem;
        margin-left: 0.1rem;
      }
    }
    .content {
      .row {
        font-size: 0.14rem;
        font-family: PingFang SC;
        font-weight: 400;
        margin-top: 0.16rem;
        display: flex;
        .r-label {
          color: #888888;
          display: block;
          // width: 0.7rem;
          //   border: 1px solid red;
        }
        .r-column {
          display: block;
          color: #191f25;
          // width: 2.5rem;
          //   border: 1px solid red;
          //    width: 1rem;
        }
      }
      .fhrow {
        margin-top: 0.16rem;
        display: flex;
        .fhImg {
          width: 0.55rem;
          height: 0.55rem;
          border-radius: 0.1rem;
        }
        .rt-column {
          width: 2.55rem;
          //   height: 2.55rem;
          margin-left: 0.2rem;
          .rt-title {
            font-size: 0.16rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: #191f25;
            margin-bottom: 0.16rem;
          }
          .rt-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 0.23rem;
            .column {
              //    border: 1px solid red;
              width: 1.5rem;
              .column-t {
                font-size: 0.14rem;
                font-family: PingFang SC;
                font-weight: 400;
                color: #888888;

                margin-bottom: 0.03rem;
              }
              .column-c {
                font-size: 0.16rem;
                font-family: PingFang SC;
                font-weight: 400;
                color: #191f25;
              }
            }
          }
        }
      }
    }
  }
  .search-bottom {
    height: 0.5rem;
    width: 100%;
    background: #ffffff;
    // background: red;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0.11rem;
    .btnconfirm {
      width: 1.72rem;
      height: 0.39rem;
      background: #1890ff;
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
    }
    .btncancel {
      width: 1.72rem;
      height: 0.39rem;
      background: #f6f6f6;
      border: 0.01px solid rgba(25, 31, 37, 0.12);
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
    }
  }
}
</style>
<style>
.van-tabs__line {
  background-color: #1890ff;
}
.van-tab--active {
  color: #1890ff;
}
</style>